﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using BookStore.Models;
using System.Dynamic;
using Microsoft.Extensions.Configuration;
using BookStore.Service;

namespace BookStore.Controllers
{
    
    public class HomeController : Controller
    {
        private readonly IConfiguration _configuration;
        private readonly IUserService _userService;
        private readonly IEmailService _emailService;

        public HomeController(IConfiguration configuration, IUserService userService, IEmailService emailService)
        {
            _configuration = configuration;
            _userService = userService;
            _emailService = emailService;
        }


        public async Task<ViewResult> Index()
        {
            UserEmailOptions options = new UserEmailOptions
            {
                ToEmails = new List<string>() { "test@gmail.com" },
                PlaceHolders = new List<KeyValuePair<string, string>>()
                {
                    new KeyValuePair<string, string>("{{UserName}}","Castle")
                }
            };

             await _emailService.SendTestEmail(options);


            //var userId = _userService.GetUserId();
            //var isLoggedIn = _userService.IsAuthenticated();


            //var newbookAlert = new NewBookAlertConfig();
            //_configuration.Bind("NewBookAlert", newbookAlert);

            //bool isDisplay = newbookAlert.DisplayNewBookAlert;
            //string bookName = newbookAlert.BookName;
            
            // var newBook = _configuration.GetSection("NewBookAlert");
            // var result = newBook.GetValue<bool>("DisplayNewBookAlert");
            // var bookName = newBook.GetValue<string>("BookName");
            
            // var res = _configuration.GetValue<bool>("NewBookAlert:DisplayNewBookAlert");
            // var bookName = _configuration.GetValue<string>("NewBookAlert:BookName");
            //
            //
            // var result = _configuration["AppName"];
            // var key1 = _configuration["infoObj:key1"];
            // var key2 = _configuration["infoObj:key2"];
            // var key3 = _configuration["infoObj:key3:key3obj1"];
            return View();
        }

       
        public ViewResult AboutUs(string name)
        {
           
            return View();
        }

        [Route("contact-us")]
        public ViewResult ContactUs()
        {
            return View();
        }
    }
}